const router = require('koa-router')()
const query = require("../db/mysql");

router.get('/user',async (ctx,next)=>{
    try{
        let sql = 'SELECT * FROM user'
        let data = await query(sql)
        return ctx.body = {
            status:200,
            data:data
        }
    }catch{err=>{
        console.log(err)
        return ctx.body = {
            status:500,
            msg:err
        }
    }}
})

router.delete('/user',async(ctx,next)=>{
    try{
        const {uId} = ctx.request.body
        let sql = 'DELETE FROM user WHERE uId = ?'
        await query(sql,[uId])
        return ctx.body = {
            status:200,
            msg:'delete success'
        }
    }catch{err=>{
        console.log(err)
        return ctx.body = {
            status:500,
            msg:err
        }
    }}
})

module.exports = router